import axios from "axios";

//创建一个axios的对象
const loginAPI = {
    baseURL: "http://localhost:9880/sso/",
    park_url: "login",
    timeout: 5000,
    login(data, callback) {
        axios.request({
            url: this.baseURL + this.park_url,
            method: "post",
            data: data,
            headers: {
                "Content-Type": "application/json;charset=UTF-8",
            },
        }).then((res) => {
            //存储token
            console.log(res,"登录结果")
            if(res.data.code === 200){
                localStorage.setItem("TOKEN", res.data.data.token);
                localStorage.setItem("ACCOUNT", data.account);
                localStorage.setItem("USER_ID", res.data.data.user.userId);
                // console.log(localStorage.getItem("USER_ID"),"成功记录USEr_ID")
                callback(res.data);
            }else{
                callback(res.data);
            }
        });
    }
}
export default loginAPI;